package com.hospital.vac.controller;

import com.auth0.jwt.JWT;
import com.hospital.vac.entity.User;
import com.hospital.vac.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @description 通用控制层
 * @return 
 * @author ANLGIN
 * @since 2023/3/9 16:27
 */

@RestController
public class BaseController {

    @Resource
    private UserMapper userMapper;

    @Autowired
    private HttpServletRequest request;

   /**
    * @description 根据token信息查询用户信息
    * @return com.hospital.vac.entity.User
    * @author ANLGIN
    * @since 2023/3/9 16:33
    */

   public User getUser() {
        String token = request.getHeader("token");
        String aud = JWT.decode(token).getAudience().get(0);
        Integer userId = Integer.valueOf(aud);
        return userMapper.selectById(userId);
    }
}
